﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Admin_quangcao : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnxoa_Click(object sender, EventArgs e)
    {
        reset();
    }

    private void reset()
    {
        txttieude.Text = "";
        txtLink.Text = "";
        txtVitri.Text = "";
        CheckBox1.Checked = false;
    }

    protected void btnthem_Click(object sender, EventArgs e)
    {
        try
        {
            String imgFile = FileUpload1.FileName;
            String imgPath = Server.MapPath("~/images/QuangCao/" + imgFile);
            FileUpload1.SaveAs(imgPath);

            String sql = String.Format("insert into Quangcao(tieude,hinhanh,link,vitri,ngaybatdau,ngayketthuc,hienthi) values('{0}','{1}','{2}',{3},'{4}','{5}',{6})",
                txttieude.Text, imgFile, txtLink.Text, txtVitri.Text, Calendar1.SelectedDate.ToString("MM/dd/yyyy"),
                Calendar2.SelectedDate.ToString("MM/dd/yyyy"), CheckBox1.Checked?1:0);

            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.ExecuteNonQuery();
            con.Close();
            reset();
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('Khong the them du lieu')</script>");
        }
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {

    }
}
